package com.geelaro.register.domain.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.springframework.format.annotation.DateTimeFormat;

//员工表
@Entity // 声明实体类(和数据表映射的类)
@Table(name ="employee") // 配置实体类和表的映射关系,省略默认小写
public class Employee {

	@Id // 声明主键的配置
	@GeneratedValue(strategy = GenerationType.IDENTITY) // 配置主键的生成策略
	private Integer id;
	
	@Column// 配置属性和字段的映射关系，省略默认列名就是属性
	private String lastName;
	private String email;
	private Integer gender; // 0:女 1:男
	
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	private Date birth;
	

	/*
		配置联系人到客户的多对一关系
		使用注解配置多对一关系
		1.配置表关系targetEntity:对方对象的字节码对象
		2.配置外键（中间表）
			@JoinColumn
	 *			name外键字段名称
	 *			referencedColumnName参照主表的主键字段名称
	 *配置外键的过程中，配置到了多的一方，就会在多的一方维护外键
	*/
	@ManyToOne(targetEntity = Department.class)
	@JoinColumn(name = "department_id",referencedColumnName = "id")
	private Department department;
	
	
	
	public Employee() {
	}

	public Employee(Integer id, String lastName, String email, Integer gender, Department department) {
		this.id = id;
		this.lastName = lastName;
		this.email = email;
		this.gender = gender;
		this.department = department;
		this.birth = new Date();
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public Integer getGender() {
		return gender;
	}

	public void setGender(Integer gender) {
		this.gender = gender;
	}

	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	public Date getBirth() {
		return birth;
	}

	public void setBirth(Date birth) {
		this.birth = birth;
	}

	@Override
	public String toString() {
		return "Employee{" + "id=" + id + ", lastName='" + lastName + '\'' + ", email='" + email + '\'' + ", gender="
				+ gender + ", department=" + department + ", birth=" + birth + '}';
	}
}
